home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / e / eiffel.lha / flc / examples / RANDOM < prev    next >
Encoding:
Text File  |  1989-08-17  |  726 b   |  40 lines

  1.  
  2. -- Random integer generator class
  3.  
  4. indexing
  5.   author: "Guichard Damien";
  6.   created: 7,November,1995;
  7.   modified: 7,Novemeber,1995
  8.  
  9. class RANDOM
  10. creation {ANY}
  11.   randomize
  12. feature {ANY}
  13.   randomize (seed:INTEGER) is
  14.     -- Reset random value.
  15.     do
  16.       z := seed
  17.     ensure
  18.       -- z = seed
  19.     end;  -- randomize
  20.   random:INTEGER is
  21.     -- Compute next random value.
  22.     local gamma:INTEGER
  23.     do
  24.       gamma :=  a * (z \\ q) - r * (z // q)
  25.       if gamma > 0 then
  26.         z := gamma
  27.       else
  28.         z := gamma + m
  29.       end
  30.       Result := z // m
  31.     end  -- random
  32. feature {NONE}
  33.   z:INTEGER;
  34.   a:INTEGER is 16_807;
  35.   m:INTEGER is 2_147_483_647;
  36.   q:INTEGER is 127_773;
  37.   r:INTEGER is 2_836
  38. end  -- class 'RANDOM'
  39.  
  40.